# Prepare HI returns
# Note: clean and rearrange 2020 HI returns
# By Dom Valentino and Chris Kenny
# libs --------------------------------------------------------------------
library(tidyverse) # select(), filter(), mutate(), etc.
library(haven) # read_dta()

# data ---------------------------------------------------------------
returns <- read.csv("../data/returns_hi/returns_hi.csv")
cvap <- read_dta("../data/modified data/county_cvap.dta") # read cvap data

# returns ---------------------------------------------------------------
final_hi <- returns %>% transmute(year = 2020, state = "HI", treat = 1, county = county, fips = NA,
                               dem_share_pres = dem_pres / (dem_pres + rep_pres), dem_share_gov = NA, dem_share_sen = NA,
                               ballots_cast = ballots_cast) %>% 
  left_join(., cvap, by = c("year", "state", "county")) %>% 
  mutate(turnout_share = ballots_cast / cvap_approx)

# save
write_csv(final_hi, "../data/analysis/analysis_hi.csv")
